package com.wxy.service;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @author 47868
 */
@Component
public class RabbitService {
    @RabbitListener(queues = "wxy.queue")
    public void wxy(Message message, Channel channel) throws IOException, InterruptedException {
        long id = message.getMessageProperties().getDeliveryTag();
        String messageString = new String(message.getBody(), StandardCharsets.UTF_8);
        System.out.println("正常消费:"+messageString);
        channel.basicAck(id,false);
    }

    @RabbitListener(queues = "dead.queue")
    public void dead(Message message,Channel channel) throws IOException {
        long id = message.getMessageProperties().getDeliveryTag();
        System.out.println("死信队列: "+ new String(message.getBody(), StandardCharsets.UTF_8));
        channel.basicAck(id,false);
    }
}
